package com.xspace.android.imcommon.interfaces;

import android.os.DeadObjectException;
import android.os.RemoteException;

import com.xspace.android.xafcommon.util.LogUtil;

import java.util.Timer;
import java.util.TimerTask;

public class LoginMg {
	private ServiceManager mServiceManager = null;

	private LoginMg() {
		mServiceManager =ImServiceConnection.getInstance().getImServiceConnection();
	}

	private static LoginMg instance = null;

	public static LoginMg getInstance() {
		if (null == instance) {
			instance = new LoginMg();
		}
		return instance;
	}


	public void userLogin(final int iocId,final String userName, final String password,final String host,final int port,final String url,final ILoginListener listener) {
		Timer mTime = new Timer();
		TimerTask mTask = new TimerTask() {
			@Override
			public void run() {
				try {
					mServiceManager.userLogin(iocId,userName, password, host,  port, url,listener);
				}
				catch (DeadObjectException e) {
					e.printStackTrace();
					LogUtil.e("--------userLogin  DeadObjectException>>>>");
					ImServiceConnection.stop();
				}
				catch(RemoteException e1){
					e1.printStackTrace();
				}
			}
		};
		mTime.schedule(mTask, 5000);
	}


	public void userLogout() {
		try {
			mServiceManager.userLogout();
		} catch (RemoteException e) {
			e.printStackTrace();
		}

	}

}